home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
pibt40s2.arc
/
KBDINTP.MOD
< prev
next >
Wrap
Text File
|
1987-05-16
|
17KB
|
260 lines
(*----------------------------------------------------------------------*)
(* Keyboard_Interrupt_Handler --- Replaces int 9 keyboard handler *)
(*----------------------------------------------------------------------*)
PROCEDURE Keyboard_Interrupt_Handler;
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Keyboard_Interrupt_Handler *)
(* *)
(* Purpose: Replaces standard interrupt 9 keyboard driver *)
(* *)
(* Calling Sequence: *)
(* *)
(* -- Called by system only! *)
(* Remarks: *)
(* *)
(* This routine replaces the standard interrupt 9 keyboard *)
(* driver so that the Alt-keypad combinations will work *)
(* properly. *)
(* *)
(* This handler is a slight modification of one by *)
(* Neil J. Rubenking. *)
(* *)
(*----------------------------------------------------------------------*)
(* STRUCTURED *) CONST
Ctrl_Keys : ARRAY[0..12] OF BYTE =
( 119, 160, 132, 161, 115, 162, 116,
163, 117, 164, 118, 165, 166 );
BEGIN (* Keyboard_Interrupt_Handler *)
INLINE(
$9C { PUSHF ;Save the flags}
/$1E { PUSH DS ;Save registers used here}
/$50 { PUSH AX}
/$53 { PUSH BX}
/$51 { PUSH CX}
{;}
/$E4/$60 { IN AL,$60 ;Read the keyboard port}
/$88/$C1 { MOV CL,AL ;Save the key in CL}
{;}
/$3C/$80 { CMP AL,$80 ;Is is a RELEASE? If so,}
/$72/$03 { JB ChkPrt ;}
/$E9/$7D/$00 { JMP NormalKey ;treat as Normal}
{;}
/$3C/$37 {ChkPrt: CMP AL,55 ;Check for PrtSc key}
/$75/$03 { JNE ChkEnt ;No -- may be Enter or keypad}
/$E9/$A7/$00 { JMP ChkPrtSc ;Yes -- process PrtSc key}
{;}
/$3C/$1C {ChkEnt: CMP AL,28 ;Check for ENTER key}
/$75/$03 { JNE ChkBS ;No -- may be backspace}
/$E9/$8B/$00 { JMP ChkEnter ;Yes -- process enter key}
{;}
/$3C/$0E {ChkBS: CMP AL,14 ;Check for backspace key}
/$75/$03 { JNE ChkKeyPad ;No -- may be keypad}
/$E9/$B9/$00 { JMP ChkBackSp ;Yes -- process backspace key}
{;}
/$3C/$47 {ChkKeyPad: CMP AL,71 ;71 = value for HOME key}
/$72/$64 { JB NormalKey ;Below Home is normal}
/$3C/$53 { CMP AL,83 ;83 = value for DEL key}
/$7F/$60 { JG NormalKey ;Above Del is normal}
{;}
/$B8/>KBD_ROM_DATA { MOV AX,>Kbd_ROM_Data}
/$8E/$D8 { MOV DS,AX ;Point DS at the ROM DATA}
/$A0/>KBD_FLAG { MOV AL,[>Kbd_Flag] ;Pick up shift key flags}
{;}
/$A8/$F3 { TEST AL,$F3 ;Check if shifts other than alt, ctrl}
/$75/$54 { JNZ NormalKey ;If so, normal}
{;}
/$88/$C3 { MOV BL,AL ;Copy shift state}
/$80/$E3/$0C { AND BL,$0C ;Remove all but Ctrl + Alt}
/$80/$FB/$0C { CMP BL,$0C ;We only want one shift --}
/$74/$4A { JE NormalKey ;If Ctrl + Alt, pass key on.}
{;}
{; If we got here w/o a jump, it's one of our}
{; special keystrokes.}
{;}
/$E8/$54/$00 {Special: CALL ReadPort ;Read the keyboard port.}
{;}
{; Figure out TURBO code for key based upon scan code.}
{; For normal keys, add nothing. For ALT keys, add 103.}
{; For control keys, special mapping is required.}
{;}
/$A8/$08 { TEST AL,8 ;Check for ALT}
/$74/$06 { JZ TestCtrl}
{;}
/$80/$C1/$67 { ADD CL,103 ;+103 converts to TURBO code for ALT}
/$E9/$12/$00 { JMP InsCode}
{;}
/$A8/$04 {TestCtrl: TEST AL,4 ;Check for CTRL}
/$74/$0E { JZ InsCode ;otherwise it is unshifted}
{;}
/$8D/$1E/>CTRL_KEYS { LEA BX,[>Ctrl_Keys] ;Get address of ctrl key table}
/$80/$E9/$47 { SUB CL,71 ;Zero origin for key}
/$30/$ED { XOR CH,CH}
/$01/$CB { ADD BX,CX ;Get offset of new key value}
/$2E/$8A/$0F { CS: MOV CL,[BX] ;Pick up TURBO value from table}
{;}
/$80/$F4/$00 {InsCode: XOR AH,0 ;}
/$88/$C8 { MOV AL,CL ;Get the key back from CL}
/$86/$C4 { XCHG AH,AL}
/$8B/$1E/>KBD_TAIL { MOV BX,[>Kbd_Tail] ;Get tail of keyboard buffer}
/$89/$07 { MOV [BX],AX ;Put the key in the buffer}
{;}
/$81/$C3/$02/$00 { ADD BX,2 ;Advance the tail pointer}
/$81/$FB/>KBD_BUFFER_END { CMP BX,>Kbd_Buffer_End ;If at end of buffer...}
/$7C/$03 { JL BufOK}
{;}
/$BB/>KBD_BUFFER { MOV BX,>Kbd_Buffer ;...set back to beginning.}
/$89/$1E/>KBD_TAIL {BufOK: MOV [>Kbd_Tail],BX}
{;}
/$B0/$20 { MOV AL,$20 ;Send the EOI to the}
/$E6/$20 { OUT $20,AL ;...interrupt controller}
{;}
/$59 { POP CX ;Restore registers}
/$5B { POP BX}
/$58 { POP AX}
/$1F { POP DS}
/$9D { POPF}
/$89/$EC { MOV SP,BP ;Undo what TURBO did at the}
/$5D { POP BP ;...start of this routine}
{;}
/$CF { IRET ;Let's blow this joint!}
{;}
{; NormalKey}
{; ;Restore registers}
/$59 {NormalKey: POP CX}
/$5B { POP BX}
/$58 { POP AX}
/$1F { POP DS}
/$9D { POPF}
/$89/$EC { MOV SP,BP ;Jump to regular keyboard interrupt}
/$5D { POP BP ;... with a FAR JUMP}
/$2E/$FF/$2E/>KBD_SAVE_IADDR2{ CS: JMP FAR [>Kbd_Save_Iaddr2]}
{;}
{; Read keyboard control port.}
{;}
/$50 {ReadPort: PUSH AX}
/$E4/$61 { IN AL,$61 ;Read keyboard control port}
/$88/$C4 { MOV AH,AL}
/$0C/$80 { OR AL,$80 ;Set the "reset" bit and}
/$E6/$61 { OUT $61,AL ; send it back to control}
/$86/$C4 { XCHG AH,AL ;Get back the control value}
/$E6/$61 { OUT $61,AL ;Send it out also}
/$58 { POP AX}
/$C3 { RET}
{;}
{; Handle Enter key. We're only interested in Alt-Enter,}
{; which we want to return as Esc + CHR( 28 ).}
{;}
/$B8/>KBD_ROM_DATA {ChkEnter: MOV AX,>Kbd_ROM_Data}
/$8E/$D8 { MOV DS,AX ;Point DS at the ROM DATA}
/$A0/>KBD_FLAG { MOV AL,[>Kbd_Flag] ;Pick up shift key flags}
{;}
/$A8/$F7 { TEST AL,$F7 ;Test for shifts other than ALT}
/$75/$D8 { JNZ NormalKey ;If so, treat as normal key.}
{;}
/$A8/$08 { TEST AL,8 ;Check for ALT}
/$74/$D4 { JZ NormalKey ;Process as normal key if not ALT}
{;}
/$80/$E9/$67 { SUB CL,103 ;Bias for ALT key code above}
/$EB/$85 { JMP Special ;Go insert ESC 28.}
{;}
{; Handle PrtSc key. We're only interested in Alt-PrtSc,}
{; which we want to return as Esc + CHR( 55 ).}
{;}
/$B8/>KBD_ROM_DATA {ChkPrtSc: MOV AX,>Kbd_ROM_Data}
/$8E/$D8 { MOV DS,AX ;Point DS at the ROM DATA}
/$A0/>KBD_FLAG { MOV AL,[>Kbd_Flag] ;Pick up shift key flags}
{;}
/$A8/$F3 { TEST AL,$F3 ;Test for shifts other than CTRL, ALT}
/$75/$C3 { JNZ NormalKey ;If so, treat as normal key.}
{;}
/$A8/$08 { TEST AL,8 ;Check for ALT}
/$75/$0B { JNZ ChkPrtSc2 ;}
{;}
/$A8/$04 { TEST AL,4 ;Check for CTRL}
/$74/$05 { JZ ChkPrtSc1 ;}
/$B1/$72 { MOV CL,114 ;}
/$E9/$02/$00 { JMP ChkPrtSc2 ;}
{;}
/$B1/$FF {ChkPrtSc1: MOV CL,255 ;Not shifted.}
{;}
/$E8/$BE/$FF {ChkPrtSc2: CALL ReadPort ;Read keyboard port.}
/$EB/$84 { JMP InsCode ;Go insert ESC + Code.}
{;}
{; Handle backspace key. We're only interested in Alt-backspace,}
{; which we want to return as Esc + CHR( 171 ).}
{;}
/$B8/>KBD_ROM_DATA {ChkBackSp: MOV AX,>Kbd_ROM_Data}
/$8E/$D8 { MOV DS,AX ;Point DS at the ROM DATA}
/$A0/>KBD_FLAG { MOV AL,[>Kbd_Flag] ;Pick up shift key flags}
{;}
/$A8/$F7 { TEST AL,$F7 ;Test for shifts other than ALT}
/$75/$A3 { JNZ NormalKey ;If so, treat as normal key.}
{;}
/$A8/$08 { TEST AL,8 ;Check for ALT}
/$74/$9F { JZ NormalKey ;Process as normal key if not ALT}
{;}
/$B1/$AB { MOV CL,171 ;Alt-backspace code}
/$E8/$A7/$FF { CALL ReadPort ;Read keyboard port}
/$E9/$6C/$FF { JMP InsCode ;Go insert ESC 171.}
);
END (* Keyboard_Interrupt_Handler *);
(*----------------------------------------------------------------------*)
(* Install_Keyboard_Handler --- Installs new interrupt 9 keyboard driver*)
(*----------------------------------------------------------------------*)
PROCEDURE Install_Keyboard_Handler;
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Install_Keyboard_Handler *)
(* *)
(* Purpose: Replaces standard interrupt 9 keyboard driver *)
(* *)
(* Calling Sequence: *)
(* *)
(* Install_Keyboard_Handler; *)
(* *)
(*----------------------------------------------------------------------*)
BEGIN (* Install_Keyboard_Handler *)
(* Set interrupt routine address *)
DOS_Set_Intrpt( Kbd_Interrupt , CSeg , OFS( Keyboard_Interrupt_Handler ) );
END (* Install_Keyboard_Handler *);
(*----------------------------------------------------------------------*)
(* Remove_Keyboard_Handler --- Removes installed interrupt 9 driver *)
(*----------------------------------------------------------------------*)
PROCEDURE Remove_Keyboard_Handler;
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Remove_Keyboard_Handler *)
(* *)
(* Purpose: Restores standard interrupt 9 keyboard driver *)
(* *)
(* Calling Sequence: *)
(* *)
(* Remove_Keyboard_Handler; *)
(* *)
(*----------------------------------------------------------------------*)
BEGIN (* Remove_Keyboard_Handler *)
(* Restore the previous interrupt pointers *)
DOS_Set_Intrpt( Kbd_Interrupt , Kbd_Save_Iaddr1, Kbd_Save_Iaddr2 );
END (* Remove_Keyboard_Handler *);